package com.yoomiito.app.ui.capture

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.model.oilcard.OilCardInfo
import com.yoomiito.app.net.YmApi

class CapturePresenter(appConfig: AppConfig) :BaseActPresenter<CaptureActivity>(appConfig){

    fun verifyCode(code:String){
        YmApi.getYmService()
                .verifyOilCardCode(code)
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<OilCardInfo>(){
                    override fun onSuccess(t: OilCardInfo?) {
                        t?.code = code
                        v.setData(t!!)
                    }

                    override fun onFail(error: ApiException?) {
                        v.showErrorTip("充值失败，该加油卡已被使用\n轻触屏幕继续扫描")
                    }

                })
    }
}